package crawl.file;

import crawl.UrlInfo;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;

public class FileStore implements Storeable {

    public void write(Iterator<UrlInfo> infoIterator) {
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter(new File("E:\\data.txt"), true));
            while (infoIterator.hasNext()) {
                UrlInfo urlInfo = infoIterator.next();
                bw.write(urlInfo.getUrl());
                bw.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bw.flush();
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
